//
//  MPCompanyMoneyRecordController.m
//  MarkPlatform
//
//  Created by xiao6 on 2018/1/4.
//  Copyright © 2018年 AT. All rights reserved.
//

#import "MPCompanyMoneyRecordController.h"
#import "MPRecordModel.h"
#import "MoneyRecordCell.h"

@interface MPCompanyMoneyRecordController ()

@property (nonatomic, strong) NSMutableArray<MPRecordModel *> *dataList;
@property (nonatomic, copy) NSString *walletId;

@end

@implementation MPCompanyMoneyRecordController
+ (instancetype)vcWithWalletId:(NSString *)walletId {
    MPCompanyMoneyRecordController *vc = [[self alloc] init];
    vc.walletId = walletId;
    return vc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showNavTitle:@"查看明细" backItem:YES];
    [self setupRefresh:self.tableView option:ATRefreshDefault];
    [self setupEmpty:self.tableView];
}

- (void)refreshData:(NSInteger)page {
    [MPHttpTool POST:@"business/enterprise/queryWalletItem"
              params:@{@"walletID" : SafeDicObj(self.walletId),
                       @"page" : @(page),
                       @"rows" : @(RefreshPageSize),}
             success:^(NSURLSessionDataTask *task, ATApiResult *result) {
                 ATRefreshModel *model = [ATRefreshModel modelWithJSON:result.data];
                 if (page == RefreshPageStart) {
                     self.dataList = [NSMutableArray array];
                 }
                 [self.dataList addObjectsFromArray:[MPRecordModel modelArrayWithJson:model.rows]];
                 [self.tableView reloadData];
                 [self endRefresh:(model.total > self.dataList.count) && model.rows.count];
             } failure:ATDefaultFailure];
}

#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MoneyRecordCell *cell = [MoneyRecordCell cellForTableView:tableView indexPath:indexPath];
    cell.companyModel = self.dataList[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [MoneyRecordCell cellHeight];
}

@end
